package com.smt.take.model.dao

import android.content.Context
import android.util.Log
import com.j256.ormlite.dao.Dao
import com.smt.take.model.beans.RecepitAddressBean


class AddressDao(val context: Context) {
    lateinit var addressDao: Dao<RecepitAddressBean, Int>

    init {
        val openHelper = TakeOutOpenHelper(context)
        addressDao = openHelper.getDao(RecepitAddressBean::class.java)
    }

    fun addRecepitAddressBean(bean: RecepitAddressBean) {
        try {
            addressDao.create(bean)
        } catch (e: Exception) {
            Log.e("addressBean", e.message.toString())
        }
    }

    fun deleteRecepitAddressBean(bean: RecepitAddressBean) {
        try {
            addressDao.delete(bean)
        } catch (e: Exception) {
            Log.e("addressBean", e.message.toString())

        }
    }

    fun updateRecepiteAddressBean(bean: RecepitAddressBean) {
        try {
            addressDao.update(bean)
        } catch (e: Exception) {
            Log.e("addressBean", e.message.toString())

        }
    }

    fun queryAllAddress(): List<RecepitAddressBean> {
        return try {
            addressDao.queryForAll()
        } catch (e: Exception) {
            Log.e("addressBean", e.message.toString())
            ArrayList<RecepitAddressBean>()
        }
    }
}